import turtle

positionHuman = (0.00, 86.00)
# 修改为鳄鱼的位置
positionCrocodile1 = (-150.00, 0.00)
positionCrocodile2 = (150.00, 0.00)
positionCrocodile3 = (0.00, 260.00)
escapeDregree = 240
# 设定距离阈值，当人到鳄鱼的距离小于此值时，认为人被追上
capture_distance = 10

turtle.pensize(3)
for x in range(100):
    turtle.color("black")
    turtle.penup()
    turtle.goto(positionHuman)
    turtle.dot(2, "brown")
    turtle.pendown()
    turtle.setheading(escapeDregree)

    lengthCrocodile1 = turtle.distance(positionCrocodile1)
    lengthCrocodile2 = turtle.distance(positionCrocodile2)
    if (x >= 2):
        if (lengthCrocodile1 > lengthCrocodile2):
            escapeDregree = escapeDregree - 20
            turtle.fd(10)
            print("1", escapeDregree)
        else:
            escapeDregree = escapeDregree + 20
            turtle.fd(10)
            print("2", escapeDregree)
    else:
        turtle.fd(10)
        print("3", escapeDregree)

    positionHuman = turtle.position()

    turtle.color("green")
    turtle.penup()
    turtle.goto(positionCrocodile1)
    turtle.dot(2, "green")
    turtle.pendown()
    positionCrocodile1ToHuman = turtle.towards(positionHuman)
    turtle.setheading(positionCrocodile1ToHuman)
    turtle.fd(15)
    positionCrocodile1 = turtle.position()

    turtle.color("red")
    turtle.penup()
    turtle.goto(positionCrocodile2)
    turtle.dot(2, "red")
    turtle.pendown()
    positionCrocodile2ToHuman = turtle.towards(positionHuman)
    turtle.setheading(positionCrocodile2ToHuman)
    turtle.fd(20)
    positionCrocodile2 = turtle.position()

    turtle.color("brown")
    turtle.penup()
    turtle.goto(positionCrocodile3)
    turtle.dot(2, "brown")
    turtle.pendown()
    positionCrocodile3ToHuman = turtle.towards(positionHuman)
    turtle.setheading(positionCrocodile3ToHuman)
    turtle.fd(20)
    positionCrocodile3 = turtle.position()

    # 检查是否被追上
    distance_to_crocodile1 = turtle.distance(positionHuman, positionCrocodile1)
    distance_to_crocodile2 = turtle.distance(positionHuman, positionCrocodile2)
    distance_to_crocodile3 = turtle.distance(positionHuman, positionCrocodile3)
    if distance_to_crocodile1 < capture_distance or distance_to_crocodile2 < capture_distance or distance_to_crocodile3 < capture_distance:
        print("人被鳄鱼追上了，模拟结束！")
        break

turtle.done()

